package com.ai.planttrees.controller;
import com.ai.planttrees.model.PrizeRecord;
import com.ai.planttrees.service.PrizeService;

import com.ai.planttrees.service.RuleTitleService;
import com.ai.planttrees.util.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;


/**
* Created by CodeGenerator on 2018/04/24.
*/
@Api(value = "奖品接口",tags = {"奖品兑换管理"})
@RestController
@RequestMapping("/prize")
public class PrizeController {
    @Resource
    private PrizeService prizeService;
    @Resource
    private RuleTitleService ruleTitleService;

    @ApiOperation(value = "奖品兑换" ,notes = "返回结果")
    @PutMapping("/")
    public synchronized Result addPrizeRecord(@ApiParam("用户活动主键") @RequestParam String userId, @ApiParam("奖品主键") @RequestParam String prizeId){
        Map rs = ruleTitleService.isOverdue();
        if(!(boolean)rs.get("code")){
            return Result.fail((String) rs.get("msg"));
        }
        PrizeRecord prizeRecord = new PrizeRecord();
        prizeRecord.setUserId(userId);
        prizeRecord.setPrizeId(prizeId);
        return prizeService.addPrizeRecords(prizeRecord);
    }

    @ApiOperation(value = "查询用户兑换信息（奖品集合）" ,notes = "返回结果")
    @GetMapping("/userId/{userId}")
    public Result selPrizeRecordByUserId(@ApiParam("用户活动主键") @PathVariable("userId") String userId){
        return prizeService.selByUserId(userId);
    }
}
